<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/7/28
  Time: 20:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

    输入员工编号:<input type="text" name="firstname" id="empno"><br>
    <button onclick="SQLdel()">确定</button><br>
    <button onclick="delback()">返回主界面</button><br>

    <script>
        //删除
        function SQLdel() {
            var xmlhttp;
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
            } else {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            console.log(xmlhttp);
            // 2. 发送Ajax请求
            xmlhttp.open("POST", "/test/SQLdelete", false);

            var text0=document.getElementById("empno");

            if(text0.value == "") {
                alert("empno is empty!!!");
                return false;
            }

            var person_del = {
                empno : text0.value,
            };

            var json = JSON.stringify(person_del);
            //alert(json);
            xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlhttp.send(json);

            //alert("send OKOKOK");
//******************************************************************************
//******************************************************************************
            xmlhttp.open("GET", "/test/SQLDEL", true);
            xmlhttp.send();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var t = xmlhttp.responseText;
                    alert(t);

                }
            };
        }

        //返回
        function delback() {
            window.location.href = "http://localhost:8080/test/6";
        }
    </script>
</body>
</html>
